package com.szit.adminserver.controller;

import com.szit.adminserver.server.AdminPermissionServer;
import com.szit.adminserver.server.AdminRoleServer;
import com.szit.adminserver.server.AdminUserServer;
import com.szit.util.Result;
import com.szit.util.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class AdminServerController {

    @Autowired
    private AdminUserServer adminUserServer;

    @Autowired
    private AdminPermissionServer adminPermissionServer;

    @Autowired
    private AdminRoleServer adminRoleServer;

    @GetMapping("send")
    public String send(){
        return "AdminServer";
    }

    @PostMapping("login")
    public Result login(@RequestBody LoginUser loginUser){
        log.info("admin-server: login");
        return adminUserServer.login(loginUser);
    }

    @PostMapping("loginOut")
    public Result loginOut(String token){
        log.info("admin-server: loginOut");
        return adminUserServer.loginOut(token);
    }

    @PostMapping("updatePasswordByUsername")
    public Result updatePasswordByUsername(@RequestBody ModifyPasswordInfo modifyPasswordInfo){
        log.info("admin-server: updatePasswordByUsername");
        return adminUserServer.updatePasswordByUsername(modifyPasswordInfo);
    }

    @PostMapping("insertAdminUser")
    public Result insertAdminUser(@RequestBody AdminUserInfo adminUserInfo){
        log.info("admin-server: insertAdminUser");
        return adminUserServer.insertAdminUser(adminUserInfo);
    }

    @PostMapping("deleteAdminUserByUserId")
    public Result deleteAdminUserByUserId(String token, Integer userId){
        log.info("admin-server: deleteAdminUserByUserId");
        return adminUserServer.deleteAdminUserByUserId(token,userId);
    }

    @PostMapping("selectAllUser")
    public Result selectAllUser(String token, Integer pageNum,Integer pageSize){
        log.info("admin-server: selectAllUser");
        return adminUserServer.selectAllUser(token,pageNum,pageSize);
    }

    @PostMapping("selectAdminUserByToken")
    public Result selectAdminUserByToken(String token){
        log.info("admin-server: selectAdminUserByToken");
        return adminUserServer.selectAdminUserByToken(token);
    }

    @PostMapping("insertAdminPermission")
    public Result insertAdminPermission(@RequestBody AdminPermissionInfo adminPermissionInfo){
        log.info("admin-server: insertAdminPermission");
        return adminPermissionServer.insertAdminPermission(adminPermissionInfo);
    }

    @PostMapping("deletePermissionById")
    public Result deletePermissionById(String token, Integer permissionId){
        log.info("admin-server: deletePermissionById");
        return adminPermissionServer.deletePermissionById(token,permissionId);
    }

    @PostMapping("updatePermissionById")
    public Result updatePermissionById(@RequestBody AdminPermissionInfo adminPermissionInfo){
        log.info("admin-server: updatePermissionById");
        return adminPermissionServer.updatePermissionById(adminPermissionInfo);
    }

    @PostMapping("selectAllPermission")
    public Result selectAllPermission(String token, Integer pageNum,Integer pageSize){
        log.info("admin-server: selectAllPermission");
        return adminPermissionServer.selectAllPermission(token,pageNum,pageSize);
    }

    @PostMapping("insertAdminRole")
    public Result insertAdminRole(@RequestBody AdminRoleInfo adminRoleInfo){
        log.info("admin-server: insertAdminRole");
        return adminRoleServer.insertAdminRole(adminRoleInfo);
    }

    @PostMapping("deleteRoleById")
    public Result deleteRoleById(String token, Integer roleId){
        log.info("admin-server: deleteRoleById");
        return adminRoleServer.deleteRoleById(token,roleId);
    }

    @PostMapping("updateRoleById")
    public Result updateRoleById(@RequestBody AdminRoleInfo adminRoleInfo){
        log.info("admin-server: updateRoleById");
        return adminRoleServer.updateRoleById(adminRoleInfo);
    }

    @PostMapping("selectAllAdminRole")
    public Result selectAllAdminRole(String token, Integer pageNum,Integer pageSize){
        log.info("admin-server: selectAllAdminRole");
        return adminRoleServer.selectAllAdminRole(token,pageNum,pageSize);
    }

    @PostMapping("updateUserRoleByUserId")
    public Result updateUserRoleByUserId(@RequestBody AdminUserRoleInfo adminUserRoleInfo){
        log.info("admin-server: updateUserRoleByUserId");
        return adminUserServer.updateUserRoleByUserId(adminUserRoleInfo);
    }

    @PostMapping("deleteAdminUserRole")
    public Result deleteAdminUserRole(@RequestBody AdminUserRoleInfo adminUserRoleInfo){
        log.info("admin-server: deleteAdminUserRole");
        return adminUserServer.deleteAdminUserRole(adminUserRoleInfo);
    }

    @PostMapping("updateRolePermissionByRoleId")
    public Result updateRolePermissionByRoleId(@RequestBody AdminRolePermissionInfo adminRolePermissionInfo){
        log.info("admin-server: updateRolePermissionByRoleId");
        return adminRoleServer.updateRolePermissionByRoleId(adminRolePermissionInfo);
    }

    @PostMapping("deleteAdminRolePermission")
    public Result deleteAdminRolePermission(@RequestBody AdminRolePermissionInfo adminRolePermissionInfo){
        log.info("admin-server: deleteAdminRolePermission");
        return adminRoleServer.deleteAdminRolePermission(adminRolePermissionInfo);
    }

}
